package com.gateway.springboot.starter.client.springcloud;

import com.gateway.client.springcloud.init.SpringCloudClientEventListener;
import com.gateway.common.utils.VersionUtils;
import com.gateway.register.client.api.GatewayClientRegisterRepository;
import com.gateway.register.common.config.PropertiesConfig;
import com.gateway.springboot.starter.client.common.config.GatewayClientCommonBeanConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @program: api-gateway
 * @description:
 * @author: YuKai Fan
 * @create: 2025/2/3 20:21
 **/
@Configuration
@ImportAutoConfiguration(GatewayClientCommonBeanConfiguration.class)
@ConditionalOnProperty(value = "gateway.register.enabled", matchIfMissing = true, havingValue = "true")
public class GatewaySpringCloudClientConfiguration {
    static {
        VersionUtils.checkDuplicate(GatewaySpringCloudClientConfiguration.class);
    }

    /**
     * Spring cloud client bean post processor.
     *
     * @param clientConfig the client config
     * @param gatewayClientRegisterRepository the gateway client register repository
     * @param env the env
     * @return the spring cloud client bean post processor
     */
    @Bean
    public SpringCloudClientEventListener springCloudClientEventListener(final PropertiesConfig clientConfig,
                                                                         final GatewayClientRegisterRepository gatewayClientRegisterRepository,
                                                                         final Environment env) {
        return new SpringCloudClientEventListener(clientConfig, gatewayClientRegisterRepository, env);
    }
}